//
//  ICLCBMessageButton.m
//  ICome
//
//  Created by Administrator on 2016/11/15.
//  Copyright © 2016年 iCom. All rights reserved.
//

#import "ICLCBMessageButton.h"
#import "ICHeaderFile.h"

@implementation ICLCBMessageButton

-(instancetype)initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame])
    {
        
    }
    return self;
}

-(void)drawRect:(CGRect)rect{
    CGSize photoSize = self.size;
    
    CGFloat w = photoSize.width;
    CGFloat h = photoSize.height;
    
    CGFloat radius = 8;
    CGFloat angleWidth = 6;
    
    
    UIBezierPath *bezierPath = [UIBezierPath bezierPath];
    bezierPath.lineWidth = 1;
    bezierPath.lineCapStyle = kCGLineCapRound;
    bezierPath.lineJoinStyle = kCGLineJoinRound;
    
     
    if (self.messageType == LCBMessageTypeOther) {
        
        [bezierPath moveToPoint:CGPointMake(w-angleWidth,h-radius)];
        [bezierPath addArcWithCenter:CGPointMake(w-radius-angleWidth, h-radius) radius:radius startAngle:0 endAngle:M_PI/2 clockwise:YES];
        [bezierPath addArcWithCenter:CGPointMake(radius, h-radius) radius:radius startAngle:M_PI/2 endAngle:M_PI clockwise:YES];
        [bezierPath addArcWithCenter:CGPointMake(radius,radius) radius:radius startAngle:M_PI endAngle:3*M_PI/2 clockwise:YES];
        [bezierPath addArcWithCenter:CGPointMake(w-radius-angleWidth, radius) radius:radius startAngle:3*M_PI/2 endAngle:2*M_PI clockwise:YES];
        [bezierPath addLineToPoint:CGPointMake(w-angleWidth,40/2-angleWidth)];
        [bezierPath addLineToPoint:CGPointMake(w, 40/2)];
        [bezierPath addLineToPoint:CGPointMake(w-angleWidth, 40/2+angleWidth)];
        
    }else
    {
        [bezierPath moveToPoint:CGPointMake(w,h-radius)];
        [bezierPath addArcWithCenter:CGPointMake(w-radius, h-radius) radius:radius startAngle:0 endAngle:M_PI/2 clockwise:YES];
        [bezierPath addArcWithCenter:CGPointMake(radius+angleWidth, h-radius) radius:radius startAngle:M_PI/2 endAngle:M_PI clockwise:YES];
        [bezierPath addLineToPoint:CGPointMake(angleWidth, 40/2+angleWidth)];
        [bezierPath addLineToPoint:CGPointMake(0, 40/2)];
        [bezierPath addLineToPoint:CGPointMake(angleWidth,40/2-angleWidth)];
        [bezierPath addArcWithCenter:CGPointMake(radius+angleWidth,radius) radius:radius startAngle:M_PI endAngle:3*M_PI/2 clockwise:YES];
        [bezierPath addArcWithCenter:CGPointMake(w-radius, radius) radius:radius startAngle:3*M_PI/2 endAngle:2*M_PI clockwise:YES];
    }
    
    [bezierPath closePath];
    
    CAShapeLayer *shapLayer = [CAShapeLayer layer];
    shapLayer.path = bezierPath.CGPath;
    
//    boarderLayer.path = bezierPath.CGPath;
//    boarderLayer.frame= photoImageView.bounds;
    
    self.layer.mask = shapLayer;
    
}

@end
